
#include "imtPublic.h"
#include "imtLock.h"

#include <windows.h>

namespace iMate {

	class _iMateExport Lock : public ILock
	{
		::CRITICAL_SECTION mSection;
	public:
		Lock()
		{
			::InitializeCriticalSection(&mSection);
		}
		virtual ~Lock()
		{
			::DeleteCriticalSection(&mSection);
		}
		virtual void lock()
		{
			::EnterCriticalSection(&mSection);
		}
		virtual void unlock()
		{
			::LeaveCriticalSection(&mSection);
		}
		virtual bool tryLock()
		{
			return ::TryEnterCriticalSection(&mSection) != FALSE;
		}
	};

	
	ILock* ILock::create()
	{
		return new Lock();
	}

}//